package com.lijian.netty.websocket5;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.datayoo.moql.sql.SqlDialectType;
import org.datayoo.moql.translator.MoqlTranslator;

/**
 * @author lj02
 * @desc
 * @date 2018/11/26
 */
public class WebSocketServer {
    public static void main(String[] args) throws Exception {


        String sql = "select t.a,sum(b) from yunying.org_signup_info t,yunying.org_signup_info t2 where t2.c=t.c and and t2.org_id in(1,2) t.org_id=1 order by sumScore";
        try{
            String es=MoqlTranslator.translateMoql2Dialect(sql,SqlDialectType.ELASTICSEARCH);
            System.out.println(es);
        }catch (Exception e){
            e.printStackTrace();
        }
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            // handler 针对 boss , childhandler 针对 worker
            serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new WebSocketInitializer());
            ChannelFuture channelFuture = serverBootstrap.bind(8080).sync();
            channelFuture.channel().closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
